#ifndef __DLIST_H__
#define __DLIST_H__

// 数据节点
struct node_st {
	void *data;
	struct node_st *prev;
	struct node_st *next;
};

// 头节点
typedef struct listhead_st {
	struct node_st node;
	int size;
}dlist_t;

typedef int (*cmp_t)(const void *data, const void *key);
typedef void (*pri_t)(const void *data);

int dlisthead_init(dlist_t **mylist, int size);

int dlist_insert(dlist_t *mylist, const void *data);

int dlist_insert_tail(dlist_t *mylist, const void *data);

int dlist_empty(const dlist_t *mylist);

void *dlist_find(const dlist_t *mylist, const void *key, cmp_t cmp);

int dlist_delete(dlist_t *mylist, const void *key, cmp_t cmp);

// 删除的变种---》获取要删除的数据后再删除
int dlist_fetch(dlist_t *mylist, const void *key, cmp_t cmp, void *data);

void dlist_traval(const dlist_t *mylist, pri_t pri);

void dlist_destroy(dlist_t **mylist);

#endif

